﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BSC_OTC_Management.Code;

namespace BSC_OTC_Management.Forms
{
    public partial class FrmRejectTransaction : Form
    {
        #region khai bao bien
        CL_Ultility _cl = new CL_Ultility();
        string tblName = ""; 
        string columnName = "";
        string value = "";

        #endregion

        public  FrmRejectTransaction(string tblName, string columnName,  string value)
        {
            InitializeComponent();
            lbReject.Text = "Xin vui lòng nhập lý do bạn từ chối!";
            this.tblName = tblName;
            this.columnName = columnName;
            this.value = value;
            LoadData();
        }

        public void LoadData()
        {
            try
            {
                string _diengiai = "";
                DataTable dt = new DataTable("RejectData");
                dt = _cl._services.GetDatatable_Where(tblName, columnName, value);
                if (dt.Rows.Count > 0)
                    _diengiai = dt.Rows[0]["DIENGIAI"].ToString();
                txtReject.Text = _diengiai;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void bttOK_Click(object sender, EventArgs e)
        {
            try
            {
                string msg = "";
                DataTable tbUpdate = new DataTable("Update");
                //add colum cần update
                tbUpdate.Columns.Add("DUYET");
                tbUpdate.Columns.Add("DIENGIAI");
                //add data
                tbUpdate.Rows.Add((int)StaticVariable.approveCase.TuChoi, txtReject.Text);
                //add datatype
                tbUpdate.Rows.Add("T", "T");

                //execute Update
                msg = _cl._services.EditRow(this.tblName, tbUpdate, this.columnName, this.value, StaticVariable.userID);

                //cap nhat thong tin nguoi duyet
                bool update = _cl._services.AddTransApprove(Code.StaticVariable.userID, this.value);
                if (!update)
                    MessageBox.Show(Code.StaticVariable.messeseboxUpdateTLLogallError, Code.StaticVariable.messeseboxLuuY);

                if (msg == Code.StaticVariable.messeseboxSuaThanhCong)
                    MessageBox.Show(StaticVariable.messeseboxHuyDuyetThanhCong, StaticVariable.messeseboxLuuY);
                else
                    MessageBox.Show(msg, StaticVariable.messeseboxLuuY);

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void bttCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
